package com.email.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import com.jgeppert.struts2.jquery.tree.result.TreeNode;
import com.opensymphony.xwork2.ActionSupport;

public class JsonTreeData extends ActionSupport {
    private static final long serialVersionUID = -2886756982077980790L;
    private List<TreeNode> nodes = new ArrayList<TreeNode>();
    private String id = "";

    @Actions( { @Action(value = "/json-tree-data", results = { @Result(name = "success", type = "json", params = {"root", "nodes" }) }) })
    public String execute() {

            TreeNode nodeA = new TreeNode();
            nodeA.setId("A" + id);
            nodeA.setTitle("Node A" + id);
            nodeA.setState(TreeNode.NODE_STATE_CLOSED);

            TreeNode nodeB = new TreeNode();
            nodeB.setId("B" + id);
            nodeB.setState(TreeNode.NODE_STATE_CLOSED);
            nodeB.setTitle("Node B" + id);

            TreeNode nodeC = new TreeNode();
            nodeC.setId("C" + id);
            nodeC.setState(TreeNode.NODE_STATE_CLOSED);
            nodeC.setTitle("Node C" + id);

            nodes.add(nodeA);
            nodes.add(nodeB);
            nodes.add(nodeC);

            return SUCCESS;
    }

    public String getJSON() {
            return execute();
    }

    public List<TreeNode> getNodes() {
            return nodes;
    }

    public void setId(String id) {
            this.id = id;
    }
}